import { EventEmitter, Uri } from "vscode";
import { ActiveEnvironmentChangedParams, EnvironmentsChangedParams, IProposedExtensionAPI } from "./apiTypes";
import { IInterpreterPathService } from "./common/types";
import { EnvPathType } from "./eqEnvironments/base/info";
import { IDiscoveryAPI } from "./eqEnvironments/base/locator";
import { IInterpreterService } from "./interpreter/contracts";
import { IServiceContainer } from "./ioc/types";

const onDidInterpretersChangedEvent = new EventEmitter<EnvironmentsChangedParams[]>();
export function reportInterpretersChanged(e: EnvironmentsChangedParams[]): void {
    onDidInterpretersChangedEvent.fire(e);
}

export function buildProposedApi(
    discoveryApi: IDiscoveryAPI,
    serviceContainer: IServiceContainer,
): IProposedExtensionAPI {
    const interpreterPathService = serviceContainer.get<IInterpreterPathService>(IInterpreterPathService);
    const interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
    const proposed: IProposedExtensionAPI = {
        environment: {
            onDidChangeExecutionDetails: interpreterService.onDidChangeInterpreterConfiguration,
            getExecutionDetails: function (resource?: Uri): Promise<{ execCommand: string[] | undefined; }> {
                throw new Error("Function not implemented.");
            },
            getActiveEnvironmentPath: function (resource?: Uri): Promise<EnvPathType | undefined> {
                throw new Error("Function not implemented.");
            },
            getEnvironmentPaths: function (): Promise<EnvPathType[] | undefined> {
                throw new Error("Function not implemented.");
            },
            setActiveEnvironment: function (path: string, resource?: Uri): Promise<void> {
                throw new Error("Function not implemented.");
            },
            getRefreshPromise: function (): Promise<void> | undefined {
                throw new Error("Function not implemented.");
            },
            onDidEnvironmentsChanged:onDidInterpretersChangedEvent.event,
            onDidActiveEnvironmentChanged:onDidActiveInterpreterChangedEvent.event
        }
    };

    return proposed;
}

const onDidActiveInterpreterChangedEvent = new EventEmitter<ActiveEnvironmentChangedParams>();

export function reportActiveInterpreterChanged(e: ActiveEnvironmentChangedParams): void {
    onDidActiveInterpreterChangedEvent.fire(e);
}
